40823112 cd2021

  • Home
    • Site Map
    • reveal
    • blog
  • Introduction
  • Collaboration
  • Stage 1
    • W1
      • 利用SSH維護倉儲
      • 建立倉儲
      • 建立Leo編輯Palican
      • 協同倉儲
    • W2
      • Project production
      • 手繪草稿
      • 初步設計與討論
    • W3
      • 錯誤排解 齒輪方向與速度
      • 錯誤排解 傳動改正
      • 產品簡化
      • 完成品
    • W4
      • 2D工程圖
      • 3D爆炸圖
      • 產品設計報告與影片
  • Stage 2
    • W5
      • Stage2 Grouping
      • 進度規劃
    • W6
      • 討論
    • W7
      • Coppeliasim方向鍵操控模擬
      • 模擬問題與排解
    • W8
      • Coppeliasim避障自走車
      • 模擬問題和排解
    • W9
      • 產品報告與模擬影片
  • Stage 3
    • W10
      • Task 1
    • W11
      • task 2-1
      • task 2-2
    • W12
      • 上課直播
    • W13
      • 小組meeting直播
      • RobotDK
    • W14
      • MTB_Robot
    • W15
      • Geometry Translation
      • Algebra Translation
    • W18
    • Final Project
  • W16
  • Product Install
    • stage1-ag10
    • stage2-ag1
    • stage3-ag1
task 2-1 << Previous Next >> W12

task 2-2

Stage2-ag1 Remote API 操控

CoppeliaSim child script :

threadFunction=function()
	-- Put your thread code here (initialization and clean-up code should not be in here)

	
	-- Some EXTERNAL commands (e.g. socket commands provided by Lua libraries)
	-- might appear as blocking to the simulator. In that case, you can define
	-- a non-blocking section as following example shows:
	--
	-- sim.setThreadIsFree(true) -- Start of the non-blocking section
	--
	-- Following 2 lines are meant as an example of EXTERNAL blocking commands:
	-- http = require("socket.http")
	-- print(http.request("http://www.google.com"))
	--
	-- sim.setThreadIsFree(false) -- End of the non-blocking section
	--
	-- While in a non-blocking section, try to avoid calling sim-functions. Also
	-- never forget to close the blocking section, otherwise V-REP will hang.
	-- Make sure you read the information related to the sim.setThreadIsFree
	-- API function in V-REP's documentation.


	-- If you wish to synchronize a threaded loop with each simulation pass,
	-- set the thread switch timing in the initialization phase of this script
	-- to the maximum (200), and manually switch thread here with the
	-- sim.switchThread() command. 
	-- ( sim.switchThread() will suspend this script's execution until next
	-- simulation pass, i.e. until the simulation time has changed )
	--
	-- Following example illustrates this:
	-- 
	-- while true do
	--     local p=sim.getObjectPosition(objHandle,-1)
	--     p[1]=p[1]+0.001
	--     sim.setObjectPosition(objHandle,-1,p)
	--     sim.switchThread()
	-- end
end

-- Put some initialization code here:
sim.setThreadSwitchTiming(2) -- Default timing for automatic thread switching

-- Here we execute the regular thread code:
res,err=xpcall(threadFunction,function(err) return debug.traceback(err) end)
if not res then
	sim.addStatusbarMessage('Lua runtime error: '..err)
end

-- Put some clean-up code here:
simRemoteApi.start(19999)

Python Remote API :

import sim as vrep
import sys
# child threaded script: 
#simExtRemoteApiStart(19999)
 
vrep.simxFinish(-1)
 
clientID = vrep.simxStart('127.0.0.1', 19999, True, True, 5000, 5)
 
if clientID!= -1:
    print("Connected to remote server")
else:
    print('Connection not successful')
    sys.exit('Could not connect')
 
errorCode,left_m_handle=vrep.simxGetObjectHandle(clientID,'left_m',vrep.simx_opmode_oneshot_wait)
 
errorCode,right_m_handle=vrep.simxGetObjectHandle(clientID,'right_m',vrep.simx_opmode_oneshot_wait)
 
if errorCode == -1:
    print('Can not find left or right motor')
    sys.exit()
 
errorCode=vrep.simxSetJointTargetVelocity(clientID,left_m_handle,-1, vrep.simx_opmode_oneshot_wait)
errorCode=vrep.simxSetJointTargetVelocity(clientID,right_m_handle,-1, vrep.simx_opmode_oneshot_wait)


task 2-1 << Previous Next >> W12

Copyright © All rights reserved | This template is made with by Colorlib